package com.xyhy.core.enums.file;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import com.xyhy.core.base.ToolConstant;
import com.xyhy.core.base.enums.BaseTagEnum;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @author robert
 * @since 2024-10-09
 */
@Getter
@AllArgsConstructor
@ApiModel("枚举：文档大类型")
public enum EFileMajorType implements BaseTagEnum {
  IMAGE("图片", ToolConstant.TAG_TYPE.PRIMARY),
  AUDIO("音频", ToolConstant.TAG_TYPE.WARNING),
  VIDEO("视频", ToolConstant.TAG_TYPE.SUCCESS),
  OTHER("其他", ToolConstant.TAG_TYPE.INFO);

  private String text;
  private String tagType;

  private static Map<String, EFileMajorType> types = new HashMap<>() {
    {
      this.put("jpg", EFileMajorType.IMAGE);
      this.put("png", EFileMajorType.IMAGE);
      this.put("gif", EFileMajorType.IMAGE);
      this.put("tif", EFileMajorType.IMAGE);
      this.put("bmp", EFileMajorType.IMAGE);
      this.put("dwg", EFileMajorType.IMAGE);
      this.put("psd", EFileMajorType.IMAGE);
      this.put("svg", EFileMajorType.IMAGE);
      this.put("mp3", EFileMajorType.AUDIO);
      this.put("mid", EFileMajorType.AUDIO);
      this.put("rmvb", EFileMajorType.VIDEO);
      this.put("flv", EFileMajorType.VIDEO);
      this.put("mp4", EFileMajorType.VIDEO);
      this.put("mpg", EFileMajorType.VIDEO);
      this.put("wmv", EFileMajorType.VIDEO);
      this.put("avi", EFileMajorType.VIDEO);
      this.put("mkv", EFileMajorType.VIDEO);
      this.put("vob", EFileMajorType.VIDEO);
      this.put("ogg", EFileMajorType.VIDEO);
      this.put("webm", EFileMajorType.VIDEO);
      this.put("wav", EFileMajorType.AUDIO);
      this.put("m4r", EFileMajorType.AUDIO);
      this.put("wma", EFileMajorType.AUDIO);
      this.put("m4a", EFileMajorType.AUDIO);
      this.put("dts", EFileMajorType.AUDIO);
      this.put("ape", EFileMajorType.AUDIO);
      this.put("aac", EFileMajorType.AUDIO);
      this.put("ac3", EFileMajorType.AUDIO);
      this.put("amr", EFileMajorType.AUDIO);
      this.put("wv", EFileMajorType.AUDIO);
      this.put("mp2", EFileMajorType.AUDIO);
      this.put("flac", EFileMajorType.AUDIO);
      this.put("mmf", EFileMajorType.AUDIO);
    }
  };

  public static EFileMajorType valueOfByType(String type) {
    return Optional.ofNullable(type).map((x) -> types.get(x)).orElse(OTHER);
  }

  public static EFileMajorType valueOfByMimeType(String mimeType) {
    if (StrUtil.contains(mimeType, "image")) {
      return IMAGE;
    } else if (StrUtil.contains(mimeType, "audio")) {
      return AUDIO;
    } else {
      return StrUtil.contains(mimeType, "video") ? VIDEO : OTHER;
    }
  }

  public String getText() {
    return this.text;
  }


}
